// @flow

import React from 'react'
import {graphql} from 'react-apollo'
import type {Fn1} from "./types";

type GetMutationComponent = Fn1<mixed, React.Component>
export const getMutationComponent: GetMutationComponent = gql => graphql(gql, {
  options: ({mutate, render, ...props}) => props,
})(({mutate, render}) => {
  return render(mutate)
})

export const MutationComponent = ({gql, options, render}) => {
  const Component = getMutationComponent(gql)
  return (<Component {...options} render={render} />)
}
